home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / out-of-phase-102-c / OutOfPhase 1.02 Source / OutOfPhase Folder / PcodeStack.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  4.1 KB  |  108 lines  |  [TEXT/KAHL]

  1. /* PcodeStack.h */
  2.  
  3. #ifndef Included_PcodeStack_h
  4. #define Included_PcodeStack_h
  5.  
  6. /* PcodeStack module depends on */
  7. /* MiscInfo.h */
  8. /* Audit */
  9. /* Debug */
  10. /* Definitions */
  11. /* Memory */
  12.  
  13. /* these are the various things you can have on the stack */
  14. typedef enum
  15.     {
  16.         esScalar EXECUTE(= -18351),
  17.         esArray,
  18.         esReturnAddress
  19.     } StackTypes;
  20.  
  21. struct StackElement;
  22. typedef struct StackElement StackElement;
  23.  
  24. /* this record is one entry in the stack */
  25. /* this is public for those who need to quickly access stack elements */
  26. #ifdef SHOW_ME_STACKELEMENT
  27. typedef struct
  28.     {
  29.         /* reference counting suggested by Abe Megahed */
  30.         void*                            Array;
  31.         long                            RefCount;
  32.     } ArrayHandleType;
  33. struct StackElement
  34.     {
  35.         union StackThangPlace
  36.             {
  37.                 long                            Integer;
  38.                 float                            Float;
  39.                 double                        Double;
  40.                 ArrayHandleType*    ArrayHandle;
  41.                 struct
  42.                     {
  43.                         union OpcodeRec*    Procedure;
  44.                         long                            Index;
  45.                     }                                ReturnAddress;
  46.             }                                Data;
  47.         StackTypes                ElementType;
  48.         /* the padding assumes that it won't add up to 16 bytes.  On the Macintosh, */
  49.         /* double is either 8 or 12 bytes and enums are 2 bytes --> 14 bytes, which */
  50.         /* makes padding 2 bytes.  On most systems where enums are 4 bytes, doubles */
  51.         /* are 8 bytes --> 12 bytes, which makes padding 4 bytes.  We may run into */
  52.         /* trouble on systems with 8-byte pointers, which will make ReturnAddress */
  53.         /* 12 bytes and ElementType (probably) 4 bytes; if this happens, then just */
  54.         /* delete the padding.  The whole reason for padding the structure out to 16 */
  55.         /* bytes is to encourage compilers to do strength reduction on array accesses */
  56.         /* to the stack. */
  57.         char                            Padding[16 - (sizeof(union StackThangPlace) + sizeof(StackTypes))];
  58.     };
  59. #endif
  60.  
  61. struct ParamStackRec;
  62. typedef struct ParamStackRec ParamStackRec;
  63.  
  64. /* create a list of parameters that will lead to a function call */
  65. ParamStackRec*        NewParamStack(void);
  66.  
  67. /* this should be called when the parameter list is completely finished to */
  68. /* dispose of all arrays that might still be stored in it */
  69. void                            DisposeParamStack(ParamStackRec* Stack);
  70.  
  71. /* this is a utility routine that disposes of an array on top of stack if it */
  72. /* isn't anywhere else on the stack.  It's used if you are about to pop the top */
  73. /* element so that you don't leave orphaned arrays floating around in memory. */
  74. /* StackPtr is the index of the top element of the stack. */
  75. void                            DisposeIfNotOnStack(StackElement* Stack, long StackPtr);
  76.  
  77. /* this is a utility routine to dispose of an array in the stack somewhere if it */
  78. /* doesn't occur in the stack anywhere else.  It's used if you are about to make */
  79. /* an assignment to the array slot to make sure arrays get disposed of properly. */
  80. /* StackPtr is the index of the top element of the stack.  Where is the index */
  81. /* of the element that is being checked. */
  82. void                            DisposeIfOnStackOnlyOnce(StackElement* Stack, long StackPtr, long Where);
  83.  
  84. /* add a parameter to the parameter stack.  If the data has to */
  85. /* be allocated dynamically, a copy is made.  True is returned if successful. */
  86. MyBoolean                    AddIntegerToStack(ParamStackRec* Stack, long IntegerValue);
  87. MyBoolean                    AddFloatToStack(ParamStackRec* Stack, float FloatValue);
  88. MyBoolean                    AddDoubleToStack(ParamStackRec* Stack, double DoubleValue);
  89. /* the ACTUAL array is added, so you no longer own it after this! */
  90. MyBoolean                    AddArrayToStack(ParamStackRec* Stack, void* Array);
  91.  
  92. /* routines for reading data from a parameter stack */
  93. long                            GetStackInteger(ParamStackRec* Stack, long Index);
  94. float                            GetStackFloat(ParamStackRec* Stack, long Index);
  95. double                        GetStackLongDouble(ParamStackRec* Stack, long Index);
  96. void*                            GetStackArray(ParamStackRec* Stack, long Index);
  97.  
  98. /* routines for obtaining internal stuff for the stack */
  99. StackElement*            GetStackBase(ParamStackRec* Stack);
  100. long                            GetStackInitialSize(ParamStackRec* Stack);
  101. long                            GetStackNumElements(ParamStackRec* Stack);
  102.  
  103. /* routine for restoring changed information to stack */
  104. void                            SetStackInformation(ParamStackRec* Stack, long NewTotalSize,
  105.                                         long NewNumElements, StackElement* NewStackAddress);
  106.  
  107. #endif
  108.